package com.lyw.gulimall.product.app;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lyw.gulimall.product.entity.SkuInfoEntity;
import com.lyw.gulimall.product.service.SkuInfoService;
import com.lyw.common.utils.R;



/**
 * sku信息
 *
 * @author liyawei
 * @email liyawei@gmail.com
 * @date 2022-05-31 11:35:50
 */
@RestController
@RequestMapping("product/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("product:skuinfo:list")
    /*
    page: 1,//当前页码
    limit: 10,//每页记录数
    sidx: 'id',//排序字段
    order: 'asc/desc',//排序方式
    key: '华为',//检索关键字
    catelogId: 0,
    brandId: 0,
    min: 0,
    max: 0
     */
    // 可以用 VO 接收
    public R list(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                  @RequestParam(value = "limit", required = false, defaultValue = "10") Integer limit,
                  @RequestParam(value = "sidx", required = false) String sidx,
                  @RequestParam(value = "order", required = false) String order,
                  @RequestParam(value = "key", required = false) String key,
                  @RequestParam(value = "catelogId", required = false) Long catelogId,
                  @RequestParam(value = "brandId", required = false) Long brandId,
                  @RequestParam(value = "min", required = false) Integer min,
                  @RequestParam(value = "max", required = false) Integer max){
        IPage<Map<String, Object>> list = skuInfoService.queryPageByCondition(page, limit, sidx, order, key, catelogId, brandId, min, max);

        return R.ok().put("page", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    // @RequiresPermissions("product:skuinfo:info")
    public R info(@PathVariable("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return R.ok().put("skuInfo", skuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("product:skuinfo:save")
    public R save(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("product:skuinfo:update")
    public R update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("product:skuinfo:delete")
    public R delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
